Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    imageUrl: {
      type: String,
      value: ''
    }
  },

  data: {
    scale: 1,
    startDistance: 0,
    currentScale: 1
  },

  methods: {
    onClose() {
      this.setData({ scale: 1 });
      this.triggerEvent('close');
    },

    preventTouchMove() {
      return false;
    },

    onTouchStart(e) {
      if (e.touches.length === 2) {
        // 计算两个触摸点之间的距离
        const distance = this.getDistance(e.touches[0], e.touches[1]);
        this.setData({
          startDistance: distance,
          currentScale: this.data.scale
        });
      }
    },

    onTouchMove(e) {
      if (e.touches.length === 2) {
        const distance = this.getDistance(e.touches[0], e.touches[1]);
        const scale = (distance / this.data.startDistance) * this.data.currentScale;
        
        // 限制缩放范围
        if (scale >= 0.5 && scale <= 3) {
          this.setData({ scale });
        }
      }
    },

    onTouchEnd() {
      this.setData({
        startDistance: 0,
        currentScale: this.data.scale
      });
    },

    getDistance(p1, p2) {
      const x = p2.clientX - p1.clientX;
      const y = p2.clientY - p1.clientY;
      return Math.sqrt(x * x + y * y);
    }
  }
}); 